﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLT_BLL;
using QLT_Public;
using QLThuoc_report;

namespace GiaoDien
{
    public partial class frm_InHoaDonBanThuoc : DevExpress.XtraEditors.XtraForm
    {
        public frm_InHoaDonBanThuoc()
        {
            InitializeComponent();
        }
        CTHoaDonBH_BLL chitietBH_bll = new CTHoaDonBH_BLL();
        private void cob_MaHD_TextChanged(object sender, EventArgs e)
        {
            try
            {
                string sql = "SELECT     dbo.tbl_CTHoaDonBH.MaHDBH, dbo.tbl_HoaDonBH.TenHD, dbo.tbl_KhachHang.TenKH, dbo.tbl_NhanVien.HoTen, dbo.tbl_CTHoaDonBH.NgayBan FROM         dbo.tbl_CTHoaDonBH INNER JOIN dbo.tbl_HoaDonBH ON dbo.tbl_CTHoaDonBH.MaHDBH = dbo.tbl_HoaDonBH.MaHDBH INNER JOIN dbo.tbl_KhachHang ON dbo.tbl_HoaDonBH.MaKH = dbo.tbl_KhachHang.MaKH INNER JOIN dbo.tbl_NhanVien ON dbo.tbl_HoaDonBH.MaNV = dbo.tbl_NhanVien.MaNV where tbl_CTHoaDonBH.MaHDBH='" + cob_MaHD.Text.Trim() + "'";
                DataTable dt = new DataTable();
                dt = chitietBH_bll.taoBang(sql);
                cob_TenHD.DataSource = dt;
                cob_TenHD.DisplayMember = "TenHD";
                cob_TenKH.DataSource = dt;
                cob_TenKH.DisplayMember = "TenKH";
                cob_NgayBanHang.DataSource = dt;
                cob_NgayBanHang.DisplayMember = "NgayBan";
                cob_NhanVien.DataSource = dt;
                cob_NhanVien.DisplayMember = "HoTen";
            }
            catch (Exception)
            { }
        }

        private void cob_MaHD_Click(object sender, EventArgs e)
        {
            string sql = "select tbl_CTHoaDonBH.MaHDBH from tbl_CTHoaDonBH group by   tbl_CTHoaDonBH.MaHDBH";
            DataTable dt = new DataTable();
            dt = chitietBH_bll.taoBang(sql);
            cob_MaHD.DataSource = dt;
            cob_MaHD.DisplayMember = "MaHDBH";
        }
        CTHoaDonBH_BLL ct = new CTHoaDonBH_BLL();
        private void bbi_in_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string sql = "select * from tbl_CTHoaDonBH where MaHDBH='"+cob_MaHD.Text.Trim()+"'";
            DataTable dt = new DataTable();
            dt = ct.taoBang(sql);
            if (dt.Rows.Count> 0)
            {
                In_HoaDon f = new In_HoaDon();
                f.MaHoaDon = int.Parse(cob_MaHD.Text);
                f.ShowDialog();
                bbi_huy_ItemClick(sender,e);
            }
            else
            XtraMessageBox.Show("Mã hóa đơn không có hoặc chưa được thanh toán!","Thông Báo",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }

        private void cob_MaHD_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsControl(e.KeyChar) && !Char.IsDigit(e.KeyChar))
                e.Handled = true;
        }

        private void bbi_huy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            cob_MaHD.ResetText();
            cob_TenHD.ResetText();
            cob_TenKH.ResetText();
            cob_NhanVien.ResetText();
            cob_NgayBanHang.ResetText();
        }

        private void bbi_thoat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }


    }
}